package main

import (
	"database/sql"
	"ecld.com/prowatcher/pb"
)

type Handler interface {
	Domain
	DBWorker
}

type Domain interface {
	Login(string, string) error                 //user login by password
	LoginByToken(string, string) (int64, error) //user login by token
	UpdateInfo(string, string) error            //login in --> update info
	TouchToken(string) (pb.Token, int64, error) //login in --> touch token
	TouchPermission(string, string) error       //login in --> touch permission
}

type DBWorker interface {
	Store() Store
	SetStore(Store)
}

type Store interface {
	Register(dbw DBWorker) error
	connect() error
	stop() error
	QueryResourcePath(string) (map[string]bool, error)
	QueryPasswd(string) (string, error)
	SimpleQueryPasswd(string) (interface{}, error)
	UpdatePasswd(string, string) error
	QueryToken(string) (*dynToken, error)
	SimpleQueryToken(string) (interface{}, error)
	UpdateToken(string, *dynToken) error
}

type dynToken struct {
	uname       string
	token       string
	valid_until int64
}

type userTB struct {
	uname       sql.NullString
	passwd      sql.NullString
	token       sql.NullString
	valid_until sql.NullInt64
}

type policyTB struct {
	id            sql.NullInt64
	resource_path sql.NullString
	uname_list    sql.NullString
	recursive     sql.NullInt64
}
